{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import connections, db"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "connections.connect(\"default\", host=\"127.0.0.1\", port=\"19530\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import utility"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['test']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "utility.list_collections()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import FieldSchema, DataType"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import FieldSchema, DataType\n",
    "# 创建数据类型为INT64的主键，且主键ID自动递增\n",
    "ID_col = FieldSchema(\n",
    "    name=\"ID\",\n",
    "    dtype=DataType.INT64,\n",
    "    is_primary=True,\n",
    "    description='主键、序号',\n",
    "    auto_id=True)\n",
    "# 创建一个768维的浮点向量\n",
    "vec_col = FieldSchema(\n",
    "    name=\"itemVec\",\n",
    "    dtype=DataType.FLOAT_VECTOR,\n",
    "    dim=768,\n",
    "    description = '向量')\n",
    "# 创建一个长度128维的字符串\n",
    "name_col = FieldSchema(\n",
    "    name = 'itemName',\n",
    "    dtype = DataType.VARCHAR,\n",
    "    max_length = 128,\n",
    "    description = '商品名称')\n",
    "# 创建double类型的浮点数\n",
    "price_col = FieldSchema(\n",
    "    name = 'itemPrice',\n",
    "    dtype = DataType.DOUBLE,\n",
    "    description = '价格')\n",
    "# 创建json格式的字段\n",
    "keywords_col = FieldSchema(\n",
    "    name = 'keywords',\n",
    "    dtype = DataType.JSON)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import CollectionSchema, Collection, connections\n",
    "# 集合所包含的字段\n",
    "schema = CollectionSchema(\n",
    "  fields=[ID_col,vec_col,name_col,price_col,keywords_col],\n",
    "  description=\"商品信息表\",\n",
    "  enable_dynamic_field=True\n",
    ")\n",
    "# 集合名称\n",
    "collection_name = \"GOODS_INFO\"\n",
    "# 构建集合后断开连接\n",
    "collection = Collection(\n",
    "    name=collection_name,\n",
    "    schema=schema,\n",
    "    using='default',\n",
    "    shards_num=2\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Status(code=0, message=)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pymilvus import Collection\n",
    "# 连接集合\n",
    "collection = Collection(\"GOODS_INFO\")  \n",
    "# 构建索引所需的参数\n",
    "index_params = {\n",
    "\"metric_type\":\"L2\",\n",
    "\"index_type\":\"IVF_FLAT\",\n",
    "\"params\":{\"nlist\":1024}\n",
    "}\n",
    "# 在向量上构建索引\n",
    "collection.create_index(\n",
    "field_name=\"itemVec\", \n",
    "index_params=index_params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "collection.load()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<LoadState: Loaded>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "utility.load_state(\"GOODS_INFO\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "expr = 'A > 0 && A <= 10'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import connections, db\n",
    "import os\n",
    "from pymilvus import (\n",
    "    connections,\n",
    "    utility,\n",
    "    FieldSchema,\n",
    "    CollectionSchema,\n",
    "    DataType,\n",
    "    Collection,\n",
    ")\n",
    "\n",
    "## milvus set up\n",
    "MILVUS_HOST = os.getenv(\"MILVUS_HOST\") \n",
    "MILVUS_PORT = os.getenv(\"MILVUS_PORT\")\n",
    "MILVUS_DATABASE = os.getenv(\"MILVUS_DATABASE\")\n",
    "\n",
    "if MILVUS_HOST == None:\n",
    "    MILVUS_HOST = \"127.0.0.1\"\n",
    "\n",
    "if MILVUS_PORT == None:\n",
    "    MILVUS_PORT = \"19530\"\n",
    "\n",
    "if MILVUS_DATABASE == None:\n",
    "    MILVUS_DATABASE = \"cbgpt\"\n",
    "\n",
    "res = connections.connect(MILVUS_DATABASE, host=MILVUS_HOST, port=MILVUS_PORT)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['test']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "utility.list_collections()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "RPC error: [create_database], <MilvusException: (code=1, message=database already exist: cbgpt)>, <Time:{'RPC start': '2024-04-11 17:35:30.547440', 'RPC error': '2024-04-11 17:35:30.548721'}>\n"
     ]
    },
    {
     "ename": "MilvusException",
     "evalue": "<MilvusException: (code=1, message=database already exist: cbgpt)>",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mMilvusException\u001b[0m                           Traceback (most recent call last)",
      "    \u001b[0;31m[... skipping hidden 1 frame]\u001b[0m\n",
      "Cell \u001b[0;32mIn[23], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m db\u001b[39m.\u001b[39;49mcreate_database(\u001b[39m\"\u001b[39;49m\u001b[39mcbgpt\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/orm/db.py:27\u001b[0m, in \u001b[0;36mcreate_database\u001b[0;34m(db_name, using, timeout)\u001b[0m\n\u001b[1;32m     21\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Create a database using provided database name\u001b[39;00m\n\u001b[1;32m     22\u001b[0m \n\u001b[1;32m     23\u001b[0m \u001b[39m:param db_name: Database name\u001b[39;00m\n\u001b[1;32m     24\u001b[0m \u001b[39m:type  db_name: str\u001b[39;00m\n\u001b[1;32m     25\u001b[0m \n\u001b[1;32m     26\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m---> 27\u001b[0m _get_connection(using)\u001b[39m.\u001b[39;49mcreate_database(db_name, timeout\u001b[39m=\u001b[39;49mtimeout)\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:127\u001b[0m, in \u001b[0;36merror_handler.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    126\u001b[0m     LOGGER\u001b[39m.\u001b[39merror(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mRPC error: [\u001b[39m\u001b[39m{\u001b[39;00minner_name\u001b[39m}\u001b[39;00m\u001b[39m], \u001b[39m\u001b[39m{\u001b[39;00me\u001b[39m}\u001b[39;00m\u001b[39m, <Time:\u001b[39m\u001b[39m{\u001b[39;00mrecord_dict\u001b[39m}\u001b[39;00m\u001b[39m>\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m--> 127\u001b[0m     \u001b[39mraise\u001b[39;00m e \u001b[39mfrom\u001b[39;00m \u001b[39me\u001b[39;00m\n\u001b[1;32m    128\u001b[0m \u001b[39mexcept\u001b[39;00m grpc\u001b[39m.\u001b[39mFutureTimeoutError \u001b[39mas\u001b[39;00m e:\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:123\u001b[0m, in \u001b[0;36merror_handler.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    122\u001b[0m     record_dict[\u001b[39m\"\u001b[39m\u001b[39mRPC start\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mstr\u001b[39m(datetime\u001b[39m.\u001b[39mdatetime\u001b[39m.\u001b[39mnow())\n\u001b[0;32m--> 123\u001b[0m     \u001b[39mreturn\u001b[39;00m func(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m    124\u001b[0m \u001b[39mexcept\u001b[39;00m MilvusException \u001b[39mas\u001b[39;00m e:\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:162\u001b[0m, in \u001b[0;36mtracing_request.<locals>.wrapper.<locals>.handler\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m    161\u001b[0m     \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mset_onetime_request_id(req_id)\n\u001b[0;32m--> 162\u001b[0m \u001b[39mreturn\u001b[39;00m func(\u001b[39mself\u001b[39;49m, \u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:102\u001b[0m, in \u001b[0;36mretry_on_rpc_failure.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    101\u001b[0m     \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 102\u001b[0m         \u001b[39mraise\u001b[39;00m e \u001b[39mfrom\u001b[39;00m \u001b[39me\u001b[39;00m\n\u001b[1;32m    103\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:68\u001b[0m, in \u001b[0;36mretry_on_rpc_failure.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m     67\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> 68\u001b[0m     \u001b[39mreturn\u001b[39;00m func(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m     69\u001b[0m \u001b[39mexcept\u001b[39;00m grpc\u001b[39m.\u001b[39mRpcError \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m     70\u001b[0m     \u001b[39m# Reference: https://grpc.github.io/grpc/python/grpc.html#grpc-status-code\u001b[39;00m\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:1155\u001b[0m, in \u001b[0;36mGrpcHandler.create_database\u001b[0;34m(self, db_name, timeout)\u001b[0m\n\u001b[1;32m   1154\u001b[0m \u001b[39mif\u001b[39;00m status\u001b[39m.\u001b[39merror_code \u001b[39m!=\u001b[39m \u001b[39m0\u001b[39m:\n\u001b[0;32m-> 1155\u001b[0m     \u001b[39mraise\u001b[39;00m MilvusException(status\u001b[39m.\u001b[39merror_code, status\u001b[39m.\u001b[39mreason)\n",
      "\u001b[0;31mMilvusException\u001b[0m: <MilvusException: (code=1, message=database already exist: cbgpt)>",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[0;31mMilvusException\u001b[0m                           Traceback (most recent call last)",
      "    \u001b[0;31m[... skipping hidden 1 frame]\u001b[0m\n",
      "Cell \u001b[0;32mIn[23], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m db\u001b[39m.\u001b[39;49mcreate_database(\u001b[39m\"\u001b[39;49m\u001b[39mcbgpt\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/orm/db.py:27\u001b[0m, in \u001b[0;36mcreate_database\u001b[0;34m(db_name, using, timeout)\u001b[0m\n\u001b[1;32m     21\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Create a database using provided database name\u001b[39;00m\n\u001b[1;32m     22\u001b[0m \n\u001b[1;32m     23\u001b[0m \u001b[39m:param db_name: Database name\u001b[39;00m\n\u001b[1;32m     24\u001b[0m \u001b[39m:type  db_name: str\u001b[39;00m\n\u001b[1;32m     25\u001b[0m \n\u001b[1;32m     26\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m---> 27\u001b[0m _get_connection(using)\u001b[39m.\u001b[39;49mcreate_database(db_name, timeout\u001b[39m=\u001b[39;49mtimeout)\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:127\u001b[0m, in \u001b[0;36merror_handler.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    126\u001b[0m     LOGGER\u001b[39m.\u001b[39merror(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mRPC error: [\u001b[39m\u001b[39m{\u001b[39;00minner_name\u001b[39m}\u001b[39;00m\u001b[39m], \u001b[39m\u001b[39m{\u001b[39;00me\u001b[39m}\u001b[39;00m\u001b[39m, <Time:\u001b[39m\u001b[39m{\u001b[39;00mrecord_dict\u001b[39m}\u001b[39;00m\u001b[39m>\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m--> 127\u001b[0m     \u001b[39mraise\u001b[39;00m e \u001b[39mfrom\u001b[39;00m \u001b[39me\u001b[39;00m\n\u001b[1;32m    128\u001b[0m \u001b[39mexcept\u001b[39;00m grpc\u001b[39m.\u001b[39mFutureTimeoutError \u001b[39mas\u001b[39;00m e:\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:123\u001b[0m, in \u001b[0;36merror_handler.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    122\u001b[0m     record_dict[\u001b[39m\"\u001b[39m\u001b[39mRPC start\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mstr\u001b[39m(datetime\u001b[39m.\u001b[39mdatetime\u001b[39m.\u001b[39mnow())\n\u001b[0;32m--> 123\u001b[0m     \u001b[39mreturn\u001b[39;00m func(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m    124\u001b[0m \u001b[39mexcept\u001b[39;00m MilvusException \u001b[39mas\u001b[39;00m e:\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:162\u001b[0m, in \u001b[0;36mtracing_request.<locals>.wrapper.<locals>.handler\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m    161\u001b[0m     \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mset_onetime_request_id(req_id)\n\u001b[0;32m--> 162\u001b[0m \u001b[39mreturn\u001b[39;00m func(\u001b[39mself\u001b[39;49m, \u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:102\u001b[0m, in \u001b[0;36mretry_on_rpc_failure.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    101\u001b[0m     \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 102\u001b[0m         \u001b[39mraise\u001b[39;00m e \u001b[39mfrom\u001b[39;00m \u001b[39me\u001b[39;00m\n\u001b[1;32m    103\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:68\u001b[0m, in \u001b[0;36mretry_on_rpc_failure.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m     67\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> 68\u001b[0m     \u001b[39mreturn\u001b[39;00m func(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m     69\u001b[0m \u001b[39mexcept\u001b[39;00m grpc\u001b[39m.\u001b[39mRpcError \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m     70\u001b[0m     \u001b[39m# Reference: https://grpc.github.io/grpc/python/grpc.html#grpc-status-code\u001b[39;00m\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:1155\u001b[0m, in \u001b[0;36mGrpcHandler.create_database\u001b[0;34m(self, db_name, timeout)\u001b[0m\n\u001b[1;32m   1154\u001b[0m \u001b[39mif\u001b[39;00m status\u001b[39m.\u001b[39merror_code \u001b[39m!=\u001b[39m \u001b[39m0\u001b[39m:\n\u001b[0;32m-> 1155\u001b[0m     \u001b[39mraise\u001b[39;00m MilvusException(status\u001b[39m.\u001b[39merror_code, status\u001b[39m.\u001b[39mreason)\n",
      "\u001b[0;31mMilvusException\u001b[0m: <MilvusException: (code=1, message=database already exist: cbgpt)>",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[0;31mMilvusException\u001b[0m                           Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[23], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m db\u001b[39m.\u001b[39;49mcreate_database(\u001b[39m\"\u001b[39;49m\u001b[39mcbgpt\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/orm/db.py:27\u001b[0m, in \u001b[0;36mcreate_database\u001b[0;34m(db_name, using, timeout)\u001b[0m\n\u001b[1;32m     20\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mcreate_database\u001b[39m(db_name: \u001b[39mstr\u001b[39m, using: \u001b[39mstr\u001b[39m \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mdefault\u001b[39m\u001b[39m\"\u001b[39m, timeout: Optional[\u001b[39mfloat\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m):\n\u001b[1;32m     21\u001b[0m \u001b[39m    \u001b[39m\u001b[39m\"\"\"Create a database using provided database name\u001b[39;00m\n\u001b[1;32m     22\u001b[0m \n\u001b[1;32m     23\u001b[0m \u001b[39m    :param db_name: Database name\u001b[39;00m\n\u001b[1;32m     24\u001b[0m \u001b[39m    :type  db_name: str\u001b[39;00m\n\u001b[1;32m     25\u001b[0m \n\u001b[1;32m     26\u001b[0m \u001b[39m    \"\"\"\u001b[39;00m\n\u001b[0;32m---> 27\u001b[0m     _get_connection(using)\u001b[39m.\u001b[39;49mcreate_database(db_name, timeout\u001b[39m=\u001b[39;49mtimeout)\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:127\u001b[0m, in \u001b[0;36merror_handler.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    125\u001b[0m     record_dict[\u001b[39m\"\u001b[39m\u001b[39mRPC error\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mstr\u001b[39m(datetime\u001b[39m.\u001b[39mdatetime\u001b[39m.\u001b[39mnow())\n\u001b[1;32m    126\u001b[0m     LOGGER\u001b[39m.\u001b[39merror(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mRPC error: [\u001b[39m\u001b[39m{\u001b[39;00minner_name\u001b[39m}\u001b[39;00m\u001b[39m], \u001b[39m\u001b[39m{\u001b[39;00me\u001b[39m}\u001b[39;00m\u001b[39m, <Time:\u001b[39m\u001b[39m{\u001b[39;00mrecord_dict\u001b[39m}\u001b[39;00m\u001b[39m>\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m--> 127\u001b[0m     \u001b[39mraise\u001b[39;00m e \u001b[39mfrom\u001b[39;00m \u001b[39me\u001b[39;00m\n\u001b[1;32m    128\u001b[0m \u001b[39mexcept\u001b[39;00m grpc\u001b[39m.\u001b[39mFutureTimeoutError \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m    129\u001b[0m     record_dict[\u001b[39m\"\u001b[39m\u001b[39mgRPC timeout\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mstr\u001b[39m(datetime\u001b[39m.\u001b[39mdatetime\u001b[39m.\u001b[39mnow())\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:123\u001b[0m, in \u001b[0;36merror_handler.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    121\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m    122\u001b[0m     record_dict[\u001b[39m\"\u001b[39m\u001b[39mRPC start\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mstr\u001b[39m(datetime\u001b[39m.\u001b[39mdatetime\u001b[39m.\u001b[39mnow())\n\u001b[0;32m--> 123\u001b[0m     \u001b[39mreturn\u001b[39;00m func(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m    124\u001b[0m \u001b[39mexcept\u001b[39;00m MilvusException \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m    125\u001b[0m     record_dict[\u001b[39m\"\u001b[39m\u001b[39mRPC error\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mstr\u001b[39m(datetime\u001b[39m.\u001b[39mdatetime\u001b[39m.\u001b[39mnow())\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:162\u001b[0m, in \u001b[0;36mtracing_request.<locals>.wrapper.<locals>.handler\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m    160\u001b[0m \u001b[39mif\u001b[39;00m req_id:\n\u001b[1;32m    161\u001b[0m     \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mset_onetime_request_id(req_id)\n\u001b[0;32m--> 162\u001b[0m \u001b[39mreturn\u001b[39;00m func(\u001b[39mself\u001b[39;49m, \u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:102\u001b[0m, in \u001b[0;36mretry_on_rpc_failure.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    100\u001b[0m         back_off \u001b[39m=\u001b[39m \u001b[39mmin\u001b[39m(back_off \u001b[39m*\u001b[39m back_off_multiplier, max_back_off)\n\u001b[1;32m    101\u001b[0m     \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 102\u001b[0m         \u001b[39mraise\u001b[39;00m e \u001b[39mfrom\u001b[39;00m \u001b[39me\u001b[39;00m\n\u001b[1;32m    103\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m    104\u001b[0m     \u001b[39mraise\u001b[39;00m e \u001b[39mfrom\u001b[39;00m \u001b[39me\u001b[39;00m\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/decorators.py:68\u001b[0m, in \u001b[0;36mretry_on_rpc_failure.<locals>.wrapper.<locals>.handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m     66\u001b[0m \u001b[39mwhile\u001b[39;00m \u001b[39mTrue\u001b[39;00m:\n\u001b[1;32m     67\u001b[0m     \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m---> 68\u001b[0m         \u001b[39mreturn\u001b[39;00m func(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m     69\u001b[0m     \u001b[39mexcept\u001b[39;00m grpc\u001b[39m.\u001b[39mRpcError \u001b[39mas\u001b[39;00m e:\n\u001b[1;32m     70\u001b[0m         \u001b[39m# Reference: https://grpc.github.io/grpc/python/grpc.html#grpc-status-code\u001b[39;00m\n\u001b[1;32m     71\u001b[0m         \u001b[39mif\u001b[39;00m e\u001b[39m.\u001b[39mcode() \u001b[39min\u001b[39;00m (\n\u001b[1;32m     72\u001b[0m             grpc\u001b[39m.\u001b[39mStatusCode\u001b[39m.\u001b[39mDEADLINE_EXCEEDED,\n\u001b[1;32m     73\u001b[0m             grpc\u001b[39m.\u001b[39mStatusCode\u001b[39m.\u001b[39mPERMISSION_DENIED,\n\u001b[0;32m   (...)\u001b[0m\n\u001b[1;32m     77\u001b[0m             grpc\u001b[39m.\u001b[39mStatusCode\u001b[39m.\u001b[39mRESOURCE_EXHAUSTED,\n\u001b[1;32m     78\u001b[0m         ):\n",
      "File \u001b[0;32m~/.conda/envs/api/lib/python3.11/site-packages/pymilvus/client/grpc_handler.py:1155\u001b[0m, in \u001b[0;36mGrpcHandler.create_database\u001b[0;34m(self, db_name, timeout)\u001b[0m\n\u001b[1;32m   1153\u001b[0m status \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_stub\u001b[39m.\u001b[39mCreateDatabase(request, timeout\u001b[39m=\u001b[39mtimeout)\n\u001b[1;32m   1154\u001b[0m \u001b[39mif\u001b[39;00m status\u001b[39m.\u001b[39merror_code \u001b[39m!=\u001b[39m \u001b[39m0\u001b[39m:\n\u001b[0;32m-> 1155\u001b[0m     \u001b[39mraise\u001b[39;00m MilvusException(status\u001b[39m.\u001b[39merror_code, status\u001b[39m.\u001b[39mreason)\n",
      "\u001b[0;31mMilvusException\u001b[0m: <MilvusException: (code=1, message=database already exist: cbgpt)>"
     ]
    }
   ],
   "source": [
    "db.create_database(\"cbgpt\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['test']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "utility.list_collections()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['default', 'cbgpt']"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "db.list_database()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['default', 'cbgpt']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "db.list_database()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
